package com.ymatou.iapi.live.service;

import org.json.JSONArray;
import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

public class GetLiveInfoCall extends YmatouBaseCall{
	
	private static String opurl = "api/live/getliveinfo";

	public GetLiveInfoCall() {
		super(EnvSetup.getSystemUrl("liveiapi"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	}
	
	/**
	 * 获取Result
	 * 
	 * @return Result
	 */
	public JSONObject getResult() {
		JSONObject Data = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Data = jo.getJSONObject("result");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}
	
	/**
	 * 获取status
	 * 
	 * @return status
	 */
	public int getStatus() {
		int status = 0;
		try {
			status = new JSONObject(getReturnData()).getInt("status");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return status;
	}
	
	/**
	 * 返回品牌品类信息
	 * 
	 * @return status
	 */
	public JSONArray getBrandOrCategoryArray(int type) {
		JSONArray array = null;
		try {
			array = getResult().getJSONArray("filterInfo");
			
			if (type == 2) {
				return new JSONObject(array.get(0).toString()).getJSONArray("list");
			} else if (type == 3) {
				return new JSONObject(array.get(1).toString()).getJSONArray("list");
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return array;
	}
}
